// app.js
import './utils/utils'
import './utils/http'
App({
  token: '',
  refresh_token: '',
  // globalData: {},
  onLaunch() {
    this.getToken('token')
    this.getToken('refresh_token')
  },
  getToken(key) {
    wx.getStorage({
      key,
      success: ({ data }) => {
        // this.token = data //token是变量，但key的值是字符串，所以要用中括号
        this[key] = data
      },
    })
  },

  setToken(token, refresh_token) {
    // 给token们拼接格式
    token = 'Bearer ' + token
    refresh_token = 'Bearer ' + refresh_token

    // 存本地
    wx.setStorageSync('token', token)
    wx.setStorageSync('refresh_token', refresh_token)
    // 存全局
    this.token = token
    this.refresh_token = refresh_token
  },
})
